﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;

namespace FasterWPF
{
    public static class RichTextExt
    {
        /// <summary>
        /// Helper method to add a Paragraph to a FlowDocument
        /// </summary>
        /// <param name="txb"></param>
        /// <returns></returns>
        public static FlowDocument AddParagraph(this FlowDocument flowDoc, string font, FontStyle fontStyle, double fontSize, Brush foreground, FontWeight fontWeight, string paragraphText)
        {
            Paragraph paraHeader = new Paragraph();

            paraHeader.FontFamily = new FontFamily(font);
            paraHeader.FontStyle = fontStyle;
            paraHeader.FontSize = fontSize;
            paraHeader.Foreground = foreground;
            paraHeader.FontWeight = fontWeight;

            paraHeader.Inlines.Add(new Run(paragraphText));
            flowDoc.Blocks.Add(paraHeader);

            return flowDoc;
        }

        /// <summary>
        /// Helper method to add a Paragraph to a FlowDocument
        /// </summary>
        /// <param name="txb"></param>
        /// <returns></returns>
        public static FlowDocument AddParagraph(this FlowDocument flowDoc, string font, FontStyle fontStyle, double fontSize, Brush foreground, FontWeight fontWeight, Run paragraphRun)
        {
            Paragraph paraHeader = new Paragraph();

            paraHeader.FontFamily = new FontFamily(font);
            paraHeader.FontStyle = fontStyle;
            paraHeader.FontSize = fontSize;
            paraHeader.Foreground = foreground;
            paraHeader.FontWeight = fontWeight;

            paraHeader.Inlines.Add(paragraphRun);
            flowDoc.Blocks.Add(paraHeader);

            return flowDoc;
        }

        public static string SetText(this TextBlock txb, string newText)
        {
            return txb.Inlines.FirstInline.Cast<System.Windows.Documents.Run>().Text = newText;
        }
               
    }//end of class
}//end of namespace
